package com.jf.blog_jf04.utils.config;

import com.jf.blog_jf04.utils.interceptor.LoginInterceptor;
import com.jf.blog_jf04.utils.interceptor.UserinfoStatusInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebAppConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private UserinfoStatusInterceptor userinfoStatusInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry
                .addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                /*排除首页*/
                .excludePathPatterns("/", "/index.html")
                /*排除上传的文件路径*/
                .excludePathPatterns("/images/**")
                /*排除swagger*/
                .excludePathPatterns("/csrf", "/swagger-resources/**", "/webjars/**", "/swagger-ui.html/**", "/doc.html/**")
                /*排除前端接口*/
                .excludePathPatterns("/api/**")
                /*排除白名单*/
                .excludePathPatterns("/login", "/kaptcha.jpg", "/forget/send/*", "/forget", "/register/send/*", "/register");
        registry.addInterceptor(userinfoStatusInterceptor)
                .addPathPatterns("/blog/**", "/category/**", "/tag/**");
    }
}
